<template>
  <div>
    <storeDiyForm :title="diyItem.name"  :hide="['other']">
      <template #content>
        <storeDiyFormItem label="模板样式">
          <storeDiyFormTempBtn
            text="选择模板"
            type="title"
            v-model="diyItem.temp"
          >
          </storeDiyFormTempBtn>
        </storeDiyFormItem>
        <storeDiyFormItem label="图片">
          <storeDiyFormImageBtn v-model="diyItem.style.icon">
          </storeDiyFormImageBtn>
        </storeDiyFormItem>
        <storeDiyFormItem label="数据来源">
          <storeDiyFormSelectBtn
            v-model="diyItem.params.source"
            :data="paramsSourceData"
          ></storeDiyFormSelectBtn>
        </storeDiyFormItem>
        <template v-if="diyItem.params.source == 'auto'">
          <draggable v-model="diyItem.data" item-key="index">
            <template #item="{ element, index }">
              <storeDiyFormItems>
                <storeDiyFormDeleteBtn
                  @click="onEditorDelele(index)"
                ></storeDiyFormDeleteBtn>
                <storeDiyFormItem label="公告内容" :hideAfter="true">
                  <el-input v-model="element.title" />
                </storeDiyFormItem>
                <storeDiyFormItem
                  label="跳转链接"
                  :hideAfter="true"
                  :marginBotton="false"
                >
                  <storeDiyFormLinkBtn
                    text="选择跳转到的页面"
                    v-model="element.link"
                  >
                  </storeDiyFormLinkBtn>
                </storeDiyFormItem>
              </storeDiyFormItems>
            </template>
          </draggable>
          <storeDiyFormCreateBtn
            @click="onEditorAddData"
            v-if="diyItem.data.length < 5"
            text="添加一个"
          >
          </storeDiyFormCreateBtn>
        </template>
      </template>

      <template #style>
        <storeDiyFormItem label="文本颜色">
          <storeDiyFormColorBtn v-model="diyItem.style.color" />
        </storeDiyFormItem>
        <storeDiyFormItem label="背景状态">
          <storeDiyFormSelectBtn
            v-model="diyItem.style.bg_status"
            :data="bgStatusData"
          ></storeDiyFormSelectBtn>
        </storeDiyFormItem>
        <storeDiyFormItem label="背景颜色" v-if="diyItem.style.bg_status">
          <storeDiyFormColorBtn v-model="diyItem.style.bg" />
        </storeDiyFormItem>
        <storeDiyFormItem label="投影样式">
          <storeDiyFormSelectBtn
            v-model="diyItem.style.shade"
            :data="shadeData"
          ></storeDiyFormSelectBtn>
        </storeDiyFormItem>

        <storeDiyFormItem
          label="背景上圆角"
          v-if="diyItem.style.bg_status == 1"
        >
          <div class="editor-input-block">
            <div class="editor-input-desc">
              {{ diyItem.style.t_radius }}px(像素)
            </div>
            <el-slider
              v-model="diyItem.style.t_radius"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem
          label="背景下圆角"
          v-if="diyItem.style.bg_status == 1"
        >
          <div class="editor-input-block">
            <div class="editor-input-desc">
              {{ diyItem.style.b_radius }}px(像素)
            </div>
            <el-slider
              v-model="diyItem.style.b_radius"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>

        <el-divider content-position="left">
          <div class="fw">边距</div>
        </el-divider>

        <storeDiyFormItem label="外左边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.ml }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.ml"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>

        <storeDiyFormItem label="外右边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.mr }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.mr"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem label="外上边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.mt }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.mt"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem label="外下边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.mb }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.mb"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>

        <storeDiyFormItem label="内左边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.pl }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.pl"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem label="内右边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.pr }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.pr"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>

        <storeDiyFormItem label="内上边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.pt }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.pt"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem label="内下边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.pb }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.pb"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
      </template>
    </storeDiyForm>
  </div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import draggable from "vuedraggable";
export default defineComponent({
  name: "storeDiyEditorNotice",
  components: {
    draggable,
  },
});
</script>
<script  lang="ts" setup >
import { ref, getCurrentInstance } from "vue";
import storeDiyForm from "../form/index.vue";
import storeDiyFormItem from "../form/item.vue";
import storeDiyFormItems from "../form/items.vue";
import storeDiyFormImageBtn from "../form/image-btn.vue";
import storeDiyFormTempBtn from "../form/temp-btn.vue";
import storeDiyFormSelectBtn from "../form/select-btn.vue";
import storeDiyFormLinkBtn from "../form/link-btn.vue";
import storeDiyFormCreateBtn from "../form/create-btn.vue";
import storeDiyFormDeleteBtn from "../form/delete-btn.vue";
import storeDiyFormColorBtn from "../form/color-btn.vue";
import { diySelectDataType, diyNoticeDataType } from "@/types";
const {
  proxy: { $utils },
} = getCurrentInstance() as any;

const props = withDefaults(
  defineProps<{
    diyItem: diyNoticeDataType;
  }>(),
  {
    diyItem: () => {
      return {
        params: {
          source: "auto",
        },
        style: {
          icon: "",
          color: "#000000",
          bg_status: 1,
          bg: "",
          shade: 0,
          mt: 0,
          mb: 0,
          ml: 0,
          mr: 0,
          pt: 0,
          pb: 0,
          pl: 0,
          pr: 0,
          t_radius: 0,
          b_radius: 0,
        },
        data: [],
        default_data: {
          title: "",
          link: {},
        },
      };
    },
  }
);

const emit = defineEmits(["onEditorAdd", "onEditorDelele"]);

/**
 * 编辑器：添加data元素
 */
const onEditorAddData = () => {
  emit("onEditorAdd", {
    count: 5,
    msg: "已超出限制公告数量",
    type: "notice",
  });
};
const onEditorDelele = (index: number) => {
  emit("onEditorDelele", {
    index,
    key: "data",
  });
};

const paramsSourceData = ref<Array<diySelectDataType>>([
  {
    title: "默认",
    value: "auto",
  },
]);

const bgStatusData = ref<Array<diySelectDataType>>([
  {
    title: "显示",
    value: 1,
  },
  {
    title: "不显示",
    value: 0,
  },
]);

const shadeData = ref<Array<diySelectDataType>>([
  {
    title: "常规",
    value: 0,
  },
  {
    title: "投影",
    value: 1,
  },
]);
</script>